package config

import (
	"fmt"
	"github.com/joho/godotenv"
	"github.com/zeromicro/go-zero/core/logx"
	"github.com/zeromicro/go-zero/core/stores/cache"
	"github.com/zeromicro/go-zero/rest"
	"os"
	"path/filepath"
)

func GetConfigFile(path string) string {
	// 加载 .env 文件
	if err := godotenv.Load(filepath.Join(path, ".env")); err != nil {
		logx.Errorf("Error loading .env file: %v", err)
	}
	env := os.Getenv("GO_ENV")
	//logx.Infof("env=: %s", env)
	//if env == "" {
	//	env = "dev" // 默认开发环境
	//}
	return filepath.Join(path, "etc", fmt.Sprintf("gozero-api-%s.yaml", env))
}

type Config struct {
	rest.RestConf
	Mysql struct {
		DataSource string
	}
	Cache cache.CacheConf
	/*
		Elasticsearch struct {
			Hosts    []string
			Username string
			Password string
		}
	*/

	//e签宝配置
	ESign struct {
		AppId      string
		AppSecret  string
		BaseUrl    string
		OrgID      string
		GrantType  string
		IsWriteLog string
	}
}
